/*
 * 컴파일을 위해 올려 놓은 소스 입니다.
 * 서버에 반영하지 마시고 다른국가에 적용할 경우 서버에 있는 class 를 카피해서 사용하십시오.
 * 
 */
/*
 * Created on 2004. 10. 4.
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.pushmsg.OmaOtaConf.OmaOtaObject; 

/**
 * @author dgchun
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class IMAP4 extends APPLICATION
{	
	String profileName = null;
	String port = null;
	String address = null;
	String id = null;
	String pwd = null;
	String apop = null;
	String security = null;
	String provider_id = null;
	
	public IMAP4(String napid)
	{
		super.appid = "143";
		super.napid = napid; 
	}
	public void setProfileName(String profileName)
	{
		this.profileName = profileName;
	}
	
	public void setAddress(String address)
	{
		this.address = address;
	}
	
	public void setPort(String port)
	{
		this.port = port;
	}
	
	public void setId(String id)
	{
		this.id = id;
	}
	
	public void setPwd(String pwd)
	{
		this.pwd = pwd;
	}
	
	public void setSecurity(String security)
	{
		this.security = security;
	}	
	
	public void setProviderId(String id)
	{
		provider_id = id;
	}
	public int getData(byte[] buffer, int index)
	{
		int startPos = index;
		//<characteristic type="APPLICATION">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x55; //type="APPLICATION"
		buffer[index++] = (byte)0x01;
		
		//<parm name="APPID" value="143"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x36;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(appid.getBytes(), 0, buffer, index, appid.length());
		index += appid.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm
		
		//<parm name="PROVIDER-ID" value="x"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x38;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		//System.out.println("POP3 PROVIDER_ID = " + provider_id);
		System.arraycopy(provider_id.getBytes(), 0, buffer, index, provider_id.length());
		index += provider_id.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm
		
		//<parm name="TO-NAPID" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x22; //name="TO-NAPID"
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(napid.getBytes(), 0, buffer, index, napid.length());
		index += napid.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm

		//<characteristic type="APPADDR">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x56; //type="APPADDR"
		buffer[index++] = (byte)0x01;
		
		//<parm name="ADDR" value="xxxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x34; //name="ADDR"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(address.getBytes(), 0, buffer, index, address.length());
		index += address.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm	
		
		//<characteristic type="PORT">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x53; //type="PORT"
		buffer[index++] = (byte)0x01;
		
		//<parm name="PORTNBR" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x23; //name="PORTNBR"
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		/*if(security!=null&&security.equals("y"))
			port = "993";*/
		System.arraycopy(port.getBytes(), 0, buffer, index, port.length());
		index += port.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm	

		if(security.equals("y")){
		//<parm name="SERVICE" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x24; //name="SERVICE"
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(port.getBytes(), 0, buffer, index, port.length());
		index += port.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		}
				
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'PORT'		
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'APPADDR'

		//<characteristic type="APPAUTH">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x57; //type="APPAUTH"
		buffer[index++] = (byte)0x01;
		/*
		//<parm name="AAUTHTYPE" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x33; //name="AAUTHTYPE"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		String aauthtype = "LOGIN";
		System.arraycopy(aauthtype.getBytes(), 0, buffer, index, aauthtype.length());
		index += aauthtype.length();		
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		*/
		//<parm name="AAUTHNAME" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 00
		buffer[index++] = (byte)0x31; //name="AAUTHNAME"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(id.getBytes(), 0, buffer, index, id.length());
		index += id.length();		
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		
		//<parm name="AAUTHSECRETE" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 00
		buffer[index++] = (byte)0x32; //name="AAUTHNAME"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(pwd.getBytes(), 0, buffer, index, pwd.length());
		index += pwd.length();		
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'APPAUTH'
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'APPLICATION'		
		return index - startPos;
	}
}


